package cn.pomelo.secondskill.controller;

import cn.pomelo.secondskill.common.AjaxResult;
import cn.pomelo.secondskill.model.Goods;
import cn.pomelo.secondskill.model.GoodsDetail;
import cn.pomelo.secondskill.service.RedisService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/goods")
public class GoodsController {

    @Resource
    RedisService redisService;


    @RequestMapping("/all")
    public AjaxResult getAll() {
        List<Goods> goodsList = redisService.list();
        return goodsList.size() > 0 ? AjaxResult.success(goodsList) : AjaxResult.failure("查询失败");
    }

    @RequestMapping("/info")
    public AjaxResult getById(Integer id) {
        GoodsDetail detail = redisService.detail(id);
        return detail == null ? AjaxResult.failure("查询失败") : AjaxResult.success(detail);
    }

}
